package gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GuiListenerForText
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{

		Display display = new Display ();
		Shell shell = new Shell (display);
		


		GridLayout layout = new GridLayout(2, false);		
		shell.setLayout(layout);
		

		
		
		
		
		Label labelStartDate = new Label (shell, SWT.NONE);
		labelStartDate.setText ("Start Date");		

		final Text textStartData = new Text (shell, SWT.NONE | SWT.BORDER);
		

		Label labelEndDate = new Label (shell, SWT.NONE);
		labelEndDate.setText ("End Date");		
		
		final Text textEndData = new Text (shell, SWT.NONE | SWT.BORDER);
		

		Label labelCalibY = new Label (shell, SWT.NONE);
		labelCalibY.setText ("End Date");		

		final Text textCalibY = new Text (shell, SWT.NONE | SWT.BORDER);


		final Button buttonData = new Button (shell, SWT.RADIO);
		buttonData.setText ("Data calibration" );

		final Button buttonYear = new Button (shell, SWT.RADIO);
		buttonYear.setText ("Year calibration" );

		

		buttonData.addSelectionListener(new SelectionListener()
		{
			
			@Override
			public void widgetSelected(SelectionEvent arg0)
			{

				textStartData.setEnabled(true);
				textEndData.setEnabled(true);
				textCalibY.setEnabled(false);
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent arg0)
			{
				// TODO Auto-generated method stub
				
			}
		});
		
		
		buttonYear.addSelectionListener(new SelectionListener()
		{
			
			@Override
			public void widgetSelected(SelectionEvent arg0)
			{


				textStartData.setEnabled(false);
				textEndData.setEnabled(false);
				textCalibY.setEnabled(true);
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent arg0)
			{
				// TODO Auto-generated method stub
				
			}
		});
		
		/*ModifyListener  textDataModList =  new ModifyListener()
		{
			
			@Override
			public void modifyText(ModifyEvent arg0)
			{
				System.out.println("--> " + textStartData.getText());
				if(textStartData.getText().length()>0 || textEndData.getText().length()>0){
					textCalibY.setEnabled(false);
				}else{

					textCalibY.setEnabled(true);
				}
			}
		};

		

		ModifyListener  textCalibModList =  new ModifyListener()
		{
			
			@Override
			public void modifyText(ModifyEvent arg0)
			{
				System.out.println("--> " + textStartData.getText());
				if(textCalibY.getText().length()>0){
					textStartData.setEnabled(false);
					textEndData.setEnabled(false);
				}else{

					textStartData.setEnabled(true);
					textEndData.setEnabled(true);
				}
			}
		};

		
		textStartData.addModifyListener(textDataModList);
		textEndData.addModifyListener(textDataModList);
		textCalibY.addModifyListener(textCalibModList);
		*/
		
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();

	}

}
